package com.utils.monitor;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.taobao.api.ApiException;
import com.taobao.pac.sdk.cp.dataobject.request.LINK_CNGREY_RULE_CONFIG.HsfParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;


/**
 * 钉钉消息工具
 *
 * @author: wsl
 * @date: 2023/11/12 21:42
 * @ClassName: DingTalkMsgUtil
 */
public class DingTalkMsgUtil {
    private static final Logger logger = LoggerFactory.getLogger(DingTalkMsgUtil.class);


    private DingTalkMsgUtil() {
    }
    public static DingTalkMsgUtil getInstance(){
        return DingTalkMsgUtilInner.DING_TALK_MSG_UTIL;
    }
    static class DingTalkMsgUtilInner{
        private final static DingTalkMsgUtil DING_TALK_MSG_UTIL = new DingTalkMsgUtil();

    }

    public static void main(String[] args) {
//        sendMsgWzbs("test");
//        sendMsg(DingMsgEnum.WZ_WAREHOUSE,"保税仓");
//        sendMsg(DingMsgEnum.ORDER_PAY,"订单");
//        sendMsg(DingMsgEnum.PLAT,"平台");
//        sendMsg(DingMsgEnum.OTHER,"其他");
        sendMsg(DingMsgEnum.SYSTEM,"主机已部署成功 cc.@王松林(萝卜)");
    }

    public static void sendMsg(DingMsgEnum msgEnum,String msg){
        if (null == msgEnum){
            return;
        }
        String url = msgEnum.getMsgUrl();
        DingTalkClient client = new DefaultDingTalkClient(url);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("text");
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        text.setContent(String.format("%s------------>%s",msgEnum.getKeywords(),msg));
        request.setText(text);
        try {
            OapiRobotSendResponse response = client.execute(request);
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }


}
